<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            display: flex;
            align-items: center;
            justify-content: space-between;
            min-width: 400px;
            width: fit-content;
            height: fit-content;
            margin: 0 auto;
            position: relative;
        }
        .nav{
            cursor: pointer;
            margin-right: 16px;
        }
        .active{
            width: 32px;
            height: 5px;
            position: absolute;
            background-color: #ffe60f;
            content: "";
            left: 0;
            transform: translateX(0);
            transition: all .7s ease;
            bottom: -5px;
        }
        .nav:hover{
            color: skyblue;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="nav">首页</div>
        <div class="nav">广告栏</div>
        <div class="nav">广场</div>
        <div class="nav">意见反馈</div>
        <div class="nav">首页</div>
        <div class="nav">广告栏</div>
        <div class="nav">广场</div>
        <div class="nav">意见反馈</div>
        <div class="nav">首页</div>
        <div class="nav">广告栏</div>
        <div class="nav">广场</div>
        <div class="nav">意见反馈</div>
        <div class="active"></div>
    </div>
</body>
<script>
   let navs = document.querySelectorAll(".nav");
   let active = document.querySelector(".active");
   navs.forEach((item,index)=>{
    item.addEventListener('click',function(){
        active.style.width = `${this.clientWidth}px`;        
        active.style.transform = `translateX(${this.offsetLeft}px)`;
    })
   })
</script>
</html>